var site_url=localStorage.getItem("site_url");
var requestStatus=false;
function getParam(){
	//当前页数
	var pageNo=$('#pageNo').val();
	//总页数
	var total_page=$('#total_page').val();
	//总条数
	var total_rows=$('#total_rows').val();
	var keyword=$('#keyword').val();
	
	var deptId=$("#search_department option:selected").val(); 
	var start=$('#search_date_start').val();
	
	var end=$('#search_date_end').val();
	
	var keyword=$('#search_keyword').val();
	var userDepartId=localStorage.getItem("departId"); 
	var param = {
		current:pageNo,
	 	deptId:deptId==undefined?userDepartId:deptId,
	 	start:start,
	 	end:end,
	 	keyword:keyword
	};
	return param;    
}
/* 财务管理的开始函数 */
function pageStart(id){
	getProject();
	//当前页数
    var pageNo=$('#pageNo').val();
    //总页数
    var total_page=$('#total_page').val();
    //总条数
    var total_rows=$('#total_rows').val();
    var keyword=$('#keyword').val();
	// getData();
	//location.href="";
	//分页
/* 	$("#page").paging({
	    pageNo: parseInt(pageNo),
	    totalPage: parseInt(total_page),
	    totalSize: total_rows,
	    callback: function(num) {
	    }
	}) */
	
	
    var deptId=$("#search_department option:selected").val(); 
    var start=$('#search_date_start').val();
    
    var end=$('#search_date_end').val();
    
    var keyword=$('#search_keyword').val();
	var userInfo=getUserInfo();
	var userDepartId=userInfo.deptId; 
 	var param = {
    	current:pageNo,
     	deptId:deptId==undefined?userDepartId:deptId,
     	start:start,
     	end:end,
     	keyword:keyword
 	};
	
	switch(id){
		//它得页面
		case 51:
			var userInfo = getUserInfo();
			var dept = getDeptById(userInfo.deptId);
			
			for(var i = 0;i<dept.length;i++){
				var gaoji,querynames = "";
				if (dept[i].type == 2) {
					gaoji = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
				}
				
				if (dept[i].type == 3){
					if(userInfo.deptId==dept[i].id){
						querynames = $('<option value="'+dept[i].id+'" selected="selected">'+dept[i].name+'</option>');
					}else{
						querynames = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
					}
				}
				
				$("#search_project").append(gaoji);
				$("#search_department").append(querynames);
			}
			getTypeData();
			getDataAdd(param);
			break;		
		//工资明细页面-不交保险
		case 521:
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			    var month = "";
				var monthNum=time.getMonth() + 1;
				//小于10月，前面加0
				if(monthNum<10){
					month = ("0" + (time.getMonth() + 1)).slice(-2);
				}
			    var today = time.getFullYear() + "-" + (month);
				$('#search_month').val(today);
				var userDepartId=userInfo.deptId; 
				var projectId=$("#search_project option:selected").val(); 
				var param = {
					current:$('#pageNo').val(),
				 	deptId:deptId==undefined?"":deptId,
					projectId:projectId,
					insurance:false,
				 	start:today,
				 	end:"",
				 	keyword:keyword
				};
			
				var userInfo = getUserInfo();
				var dept = getDeptById(userInfo.deptId);
				
				for(var i = 0;i<dept.length;i++){
					var gaoji,querynames = "";
					if (dept[i].type == 2) {
						gaoji = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
					}
					
					if (dept[i].type == 3){
						if(userInfo.deptId==dept[i].id){
							querynames = $('<option value="'+dept[i].id+'" selected="selected">'+dept[i].name+'</option>');
						}else{
							querynames = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
						}
					}
					
					$("#search_project").append(gaoji);
					$("#search_department").append(querynames);
				}
				getDataSalary(param);
				
			break;
		//工资明细页面-缴纳保险
		case 522:
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			    var month = "";
				var monthNum=time.getMonth() + 1;
				//小于10月，前面加0
				if(monthNum<10){
					month = ("0" + (time.getMonth() + 1)).slice(-2);
				}
			    var today = time.getFullYear() + "-" + (month);
				$('#search_month').val(today);	
				var userDepartId=userInfo.deptId; 
				var projectId=$("#search_project option:selected").val(); 
				
				var param = {
					current:$('#pageNo').val(),
				 	deptId:deptId==undefined?"":deptId,
					projectId:projectId,
					insurance:true,
				 	start:today,
				 	end:"",
				 	keyword:keyword
				};
				
				var userInfo = getUserInfo();
				var dept = getDeptById(userInfo.deptId);
				
				for(var i = 0;i<dept.length;i++){
					var gaoji,querynames = "";
					if (dept[i].type == 2) {
						gaoji = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
					}
					
					if (dept[i].type == 3){
						if(userInfo.deptId==dept[i].id){
							querynames = $('<option value="'+dept[i].id+'" selected="selected">'+dept[i].name+'</option>');
						}else{
							querynames = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
						}
					}
					
					$("#search_project").append(gaoji);
					$("#search_department").append(querynames);
				}
				getDataSalaryPay(param);	
			break;
		//缴存基数页面
		case 53:
			var userInfo = getUserInfo();
			var dept = getDeptById(userInfo.deptId);
			
			for(var i = 0;i<dept.length;i++){
				var gaoji,querynames = "";
				if (dept[i].type == 2) {
					gaoji = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
				}
				
				if (dept[i].type == 3){
					if(userInfo.deptId==dept[i].id){
						querynames = $('<option value="'+dept[i].id+'" selected="selected">'+dept[i].name+'</option>');
					}else{
						querynames = $('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
					}
				}
				
				$("#search_project").append(gaoji);
				$("#search_department").append(querynames);
			}
			getDataBase(param);
			break;	
		default:
			break;
	}	
/* 	$("#page").paging({
		pageNo: parseInt(pageNo),
		totalPage: parseInt(total_page),
		totalSize: total_rows,
		callback: function(num) {
		}
	}) */
}
/* 工资明细 */
function salaryParam(insurance){
	var time = new Date();
	var day = ("0" + time.getDate()).slice(-2);
	var month = "";
		var monthNum=time.getMonth() + 1;
		//小于10月，前面加0
		if(monthNum<10){
			month = ("0" + (time.getMonth() + 1)).slice(-2);
		}
	    var today = time.getFullYear() + "-" + (month);
		$('#search_month').val(today);	
		var keyword=$('#search_keyword').val();
		var deptId=$("#search_department option:selected").val(); 
		var projectId=$("#search_project option:selected").val(); 
		var param = {
			current:$('#pageNo').val(),
		 	deptId:deptId==undefined?"1":deptId,
			projectId:projectId,
			insurance:insurance,
		 	start:today,
		 	end:"",
		 	keyword:keyword
		};
		return param;    
}
/* 项目部赋值 */
function getProject(){
	
	var userInfo=getUserInfo();
	var userDepartId=userInfo.deptId;
	$("#department_edit").html("");
	$("#department").html("");
	/* $("#search_department").html("");
	$("#department_edit").html(""); */
	var URL = site_url+"/depts/all";
	var userToken=localStorage.getItem("userToken");
	var result=[];
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		async:false,
		success:function(data){
			var all = "";
			result = data
			for(var i = 0;i<data.length;i++){
				all += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
			}
			$("#department").append(all);
		},
	});
	return result;
}

/* 获取用户信息 */
function getUserInfo(){

		var userToken=localStorage.getItem("userToken");
		var URL=site_url+"/login/user";
		var user="";
		$.ajax({
		    type: 'GET',
		    url: URL,
		    dataType:"json",
			headers:{'token':userToken},
			async:false,
		    success: function (json) {
				user=json.data;
		    }
		});
		return user;
}
/* 获取它得加班类型数据 */
function getTypeData(){
	$("#content").html("");
	$("#content_edit").html("");
	var URL = site_url+"/dicts/extra";
		var userToken=localStorage.getItem("userToken");
		$.ajax({
			type:"get",
			url:URL,
			headers:{'token':userToken},
			success:function(json){
				var data=json.data;
				var querynames = "";
				for(var i = 0;i<data.length;i++){
					querynames += '<option value="'+data[i].id+'">'+data[i].label+'</option>';
				}
				$("#content").append(querynames);
				$("#content_edit").append(querynames);
			}
		});
}
//给它得页面赋值
function getDataAdd(param){
	
	var userToken=localStorage.getItem("userToken");
	var URL = site_url+"/extras/page?size=10&current="+param.current+"&deptId="+param.deptId+"&start="+param.start+"&end="+param.end+"&keyword="+param.keyword;
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			var result = data.data.records;
			$('#data').html("");
			var html="";
			html+='<table>';
			html+='<tr class="table-top">';
			html+='<td width="10%">姓名</td><td width="10%">部门</td><td width="15%">电话</td><td width="10%">类别</td>';
			html+='<td width="8%">金额(元)</td><td width="15%">日期</td><td width="20%">备注</td><td width="12%">操作</td></tr>';
		
			for (var i=0;i<result.length;i++) {
				if(i%2==0){
					html+='<tr class="item-white">';
				}else{
					html+='<tr class="item-blue">';
				}
				
				html+='<td>'+result[i].userName+'</td>';
				html+='<td>'+result[i].deptName+'</td>';
				html+='<td>'+result[i].phone+'</td>';
				var name =result[i].name==null?"":result[i].name;
				html+='<td>'+name+'</td>';
				// html+='<td>'+result[i].typeName+'</td>';
				html+='<td>'+result[i].money+'</td>';
				html+='<td>'+result[i].extraTime+'</td>';
				html+='<td>'+result[i].remark+'</td>';
				html+='<td>';
				html+='<img id="edit" src="img/edit_icon.png" onclick="dateEdit(1,\''+result[i].id+'\');"/>';
				html+='<img id="delete" style="margin-left: 10px;" src="img/delete_icon.png" onclick="dateDelete(1,\''+result[i].id+'\');"/>';
				html+='</td>';
				html+='</tr>';
			}
			if(result.length<=0){
				html+='<tr class="item-white">';
				html+='<td colspan="8"><div>暂无数据</div></td>';
				html+='</tr>';
				$("#page").html("");
			}else{
				var pageNo=data.data.current;
				var total_page=data.data.pages;
				localStorage.setItem("total_page",total_page);
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						var total_page=localStorage.getItem("total_page");
						$("#page").paging({
						    pageNo: parseInt(num),
						    totalPage: parseInt(total_page)
						})
						var paramData=getParam();
						getDataAdd(paramData);
						$("#page").stopPagination({});
				    }
				})
			}
			html+='</table>';
			$('#data').html(html);
			
		}
	});
}
//给缴费基数页面赋值
function getDataBase(param){
	
	var userToken=localStorage.getItem("userToken");
	var URL = site_url+"/salarys/deposit/base?size=10&current="+param.current+"&deptId="+param.deptId+"&start="+param.start+"&end="+param.end+"&keyword="+param.keyword;
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			$('#data').html("");
			var result = data.data.records;
			var html="";
			html+='<table>';
			html+='<tr class="table-top">';
			html+='<td width="4%"></td><td width="5%">序号</td><td width="8%">部门</td><td width="8%">姓名</td><td width="6%">职工</br>工资</td>';
			html+='<td width="10%">缴费</br>基数</td><td width="10%">养老个人</br>缴费额</td><td width="10%">医疗个人</br>缴费额</td>';
			html+='<td width="10%">失业个人</br>缴费额</td><td width="10%">生育个人</br>缴费额</td><td width="10%">工伤个人</br>缴费额</td><td width="9%">操作</td></tr>';				

			for (var i=0;i<result.length;i++) {
				if(i%2==0){
					html+='<tr class="item-white">';
				}else{
					html+='<tr class="item-blue">';
				}

				html+='<td></td>';
				html+='<td>'+(i+1)+'</td>';
				html+='<td>'+result[i].deptName+'</td>';
				html+='<td>'+result[i].userName+'</td>';	
				html+='<td>'+(result[i].gangwei==null?0:result[i].gangwei)+'</td>';
				html+='<td>'+(result[i].wxjishu==null?0:result[i].wxjishu)+'</td>';
				html+='<td>'+(result[i].yanglao==null?0:result[i].yanglao)+'</td>';
				html+='<td>'+(result[i].yiliao==null?0:result[i].yiliao)+'</td>';
				html+='<td>'+(result[i].shiye==null?0:result[i].shiye)+'</td>';
				html+='<td>'+(result[i].shengyu==null?0:result[i].shengyu)+'</td>';
				html+='<td>'+(result[i].gongshang==null?0:result[i].gongshang)+'</td>';
				html+='<td>';
				html+='<img id="edit" src="img/edit_icon.png" onclick="dateEdit(4,\''+result[i].userId+'\');"/>';
				// html+='<img id="delete" style="margin-left: 10px;" src="img/delete_icon.png" onclick="dateDelete(4,\''+result[i].id+'\');"/>';
				html+='</td>';
				html+='</tr>';
			}
			if(result.length<=0){
				html+='<tr class="item-white">';
				html+='<td colspan="12"><div>暂无数据</div></td>';
				html+='</tr>';
				$("#page").html("");
			}else{
				var pageNo=data.data.current;
				var total_page=data.data.pages;
				localStorage.setItem("total_page",total_page);
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						var total_page=localStorage.getItem("total_page");
						$("#page").paging({
						    pageNo: parseInt(num),
						    totalPage: parseInt(total_page)
						})
						var paramData=getParam();
						getDataBase(paramData);
						$("#page").stopPagination({});
				    }
				})
			}
			html+='</table>';
			$('#data').html(html);
		}
	})
}
//给工资明细-不交五险页面赋值
function getDataSalary(param){
	// alert(param.start);
	var userToken=localStorage.getItem("userToken");
	var URL = site_url+"/salarys/record?size=10&current="+param.current+"&start="+param.start+"&keyword="+param.keyword+"&insurance="+param.insurance;
	var deptId=param.deptId;
	if(param.deptId==-1 || deptId==undefined){
		URL+="&projectId="+param.projectId;
	}else{
		URL+="&deptId="+param.deptId;
	}
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			var result = data.data.salarys.records;
			
			var totalSalary=data.data.totalSalary;
			var total_person=data.data.salarys.total;
			$('#total_person').text("共计："+total_person+"人");
			// $('#total_money').text("薪资共计："+totalSalary+"元");
			$('#total_money').text("薪资走势图");
			// alert(totalSalary);
			// $('#data_one').html("");
			$('#data_one').empty();
			var html="";
			html+='<table>';
			html+='<tr class="table-top">';
			html+='<td width="6%">序号</td><td width="10%">姓名</td><td width="10%">部门</td><td width="10%">职务</td><td width="10%">岗位工资</td><td width="10%">工龄工资</td>';
			html+= '<td width="8%">请假</td><td width="8%">它得</td><td width="8%">加班费用</td><td width="8%">实发工资</td><td width="12%">操作</td></tr>';
			for (var i=0;i<result.length;i++) {
				var dataArr=JSON.stringify(result[i]);
				sessionStorage.setItem(result[i].userId,dataArr);
				if(i%2==0){
					html+='<tr class="item-white">';
				}else{
					html+='<tr class="item-blue">';
				}
				html+='<td>'+(i+1)+'</td>';
				html+='<td>'+result[i].userName+'</td>';
				html+='<td>'+result[i].deptName+'</td>';
				html+='<td>'+result[i].job+'</td>';
				html+='<td>'+result[i].gangwei+'</td>';
				html+='<td>'+result[i].gongling+'</td>';
				html+='<td>'+result[i].qingjia+'</td>';
				var extra =result[i].extra==null?"0":result[i].extra;
				html+='<td>'+extra+'</td>';
				var jiaban =result[i].jiaban==null?"0":result[i].jiaban;
				html+='<td>'+jiaban+'</td>';
				var shifa =result[i].shifa==null?"0":result[i].shifa;
				html+='<td>'+shifa+'</td>';
				html+='<td>';
				html+='<img id="edit" src="img/check_icon.png" onclick="setSalaryData(1,\''+result[i].userId+'\');"/>';
				// html+='<img id="delete" style="margin-left: 10px;" src="img/delete_icon.png" onclick="dateDelete(2,'+result[i].id+');"/>';
				html+='</td>';
				html+='</tr>';
			}
			if(result.length<=0){
				html+='<tr class="item-white">';
				html+='<td colspan="11"><div>暂无数据</div></td>';
				html+='</tr>';
				$("#page").html("");
			}else{
				var pageNo=data.data.salarys.current;
				var total_page=data.data.salarys.pages;
				localStorage.setItem("total_page",total_page);
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						var total_page=localStorage.getItem("total_page");
						$("#page").paging({
						    pageNo: parseInt(num),
						    totalPage: parseInt(total_page)
						})
						var paramData=salaryParam(false);
						paramData.start=$('#search_month').val();
						getDataSalary(paramData);
						$("#page").stopPagination({});
				    }
				})
			}
			html+='</table>';
			$('#data_one').html(html);
	
		}
	});
}
//给工资明细-交纳五险页面赋值
function getDataSalaryPay(param){
	var userToken=localStorage.getItem("userToken");
	var URL = site_url+"/salarys/record?size=10&current="+param.current+"&start="+param.start+"&keyword="+param.keyword+"&insurance="+param.insurance;
	var deptId=param.deptId;
	if(param.deptId==-1 || deptId==undefined){
		URL+="&projectId="+param.projectId;
	}else{
		URL+="&deptId="+param.deptId;
	}
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			var result = data.data.salarys.records;
			$('#data_two').html("");
			var totalSalary=data.data.totalSalary;
			var total_person=data.data.salarys.total;
			$('#total_person').text("共计"+total_person+"人");
			// $('#total_money').text("薪资共计"+totalSalary+"元");
			$('#total_money').text("薪资走势图");
			
			// alert(result.length);
			var html="";
			html+='<table>';
			html+='<tr class="table-top">';
			html+='<td width="4%">序号</td><td width="6%">姓名</td><td width="6%">部门</td><td width="6%">职务</td><td width="6%">工龄</td>';
			html+= '<td width="6%">岗位</br>工资</td><td width="6%">保障</br>工资</td><td width="6%">工资</br>合计</td><td width="6%">';
			html+= '它得</br>费用</td><td width="6%">加班</br>费用</td><td width="6%">养老</br>保险</td><td width="6%">医疗</br>保险</td>';						
			html+='<td width="6%">失业</br>保险</td><td width="6%">生育</br>保险</td><td width="6%">工伤</br>保险</td><td width="6%">实发</br>工资</td><td width="6%">操作</td></tr>';
			
			for (var i=0;i<result.length;i++) {
				var dataArr=JSON.stringify(result[i]);
				sessionStorage.setItem(result[i].userId,dataArr);
				// alert(dataArr['userName']);
				if(i%2==0){
					html+='<tr class="item-white">';
				}else{
					html+='<tr class="item-blue">';
				}
				
				html+='<td>'+(i+1)+'</td>';
				html+='<td>'+result[i].userName+'</td>';
				html+='<td>'+result[i].deptName+'</td>';
				html+='<td>'+result[i].job+'</td>';
				html+='<td>'+result[i].gongling+'</td>';
				html+='<td>'+result[i].gangwei+'</td>';
				var baozhang =result[i].baozhang==null?"0":result[i].baozhang;
				html+='<td>'+baozhang+'</td>';
				var heji =result[i].heji==null?"0":result[i].heji;
				html+='<td>'+heji+'</td>';
				var extra =result[i].extra==null?"0":result[i].extra;
				html+='<td>'+extra+'</td>';
				var jiaban =result[i].jiaban==null?"0":result[i].jiaban;
				html+='<td>'+jiaban+'</td>';
				var yanglao =result[i].yanglao==null?"0":result[i].yanglao;
				html+='<td>'+yanglao+'</td>';
				var yiliao =result[i].yiliao==null?"0":result[i].yiliao;
				html+='<td>'+yiliao+'</td>';
				var shiye =result[i].shiye==null?"0":result[i].shiye;
				html+='<td>'+shiye+'</td>';
				var shengyu =result[i].shengyu==null?"0":result[i].shengyu;
				html+='<td>'+shengyu+'</td>';
				var gongshang =result[i].gongshang==null?"0":result[i].gongshang;
				html+='<td>'+gongshang+'</td>';
				var shifa =result[i].shifa==null?"0":result[i].shifa;
				html+='<td>'+shifa+'</td>';
				
				html+='<td>';
				html+='<img id="edit" src="img/check_icon.png" onclick="setSalaryData(2,\''+result[i].userId+'\');"/>';
				// html+='<img id="delete" style="margin-left: 10px;" src="img/delete_icon.png" onclick="dateDelete(3,'+result[i].id+');"/>';
				html+='</td>';
				html+='</tr>';
			}
			if(result.length<=0){
				html+='<tr class="item-white">';
				html+='<td colspan="17"><div>暂无数据</div></td>';
				html+='</tr>';
				$("#page").html("");
			}else{
				var pageNo=data.data.salarys.current;
				var total_page=data.data.salarys.pages;
				localStorage.setItem("total_page",total_page);
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						var total_page=localStorage.getItem("total_page");
						$("#page").paging({
						    pageNo: parseInt(num),
						    totalPage: parseInt(total_page)
						})
						var paramData=salaryParam(true);
						paramData.start=$('#search_month').val();
						getDataSalaryPay(paramData);
						$("#page").stopPagination({});
				    }
				})
			}
			html+='</table>';
			$('#data_two').html(html);
		}
	});
}
/* 工资单明细的查看数据赋值 */
function setSalaryData(type,id){
	var param=sessionStorage.getItem(id);
	var param=JSON.parse(param);
	// var param= JSON.stringify(param);
	// alert(param.userName);
	switch(type){
		/* 工资明细（不交五险） */
		case 1:
			$("#department_edit").val(param.deptName); 
			$("#username_edit").val(param.userName);
			$("#position_edit").val(param.job); 
			$("#post_salary_edit").val(param.gongling);  
			$("#age_salary_edit").val(param.gangwei); 
			if(param.extra==null){
				param.extra=0; 
			}
			$("#other_salary_edit").val(param.extra); 
			$("#overtime_salary_edit").val(param.jiaban);
			$("#real_salary_edit").val(param.shifa);   
			$("#late_edit").val(param.chidao);
			$("#leave_early_edit").val(param.zaotui);   
			break;
		/* 工资明细（交纳五险）  */
		case 2:
			$("#department_edit").val(param.deptName); 
			$("#username_edit").val(param.userName);     
			$("#position_edit").val(param.job);       
			$("#post_salary_edit").val(param.gongling);   
			$("#age_salary_edit").val(param.gangwei);       
			$("#other_salary_edit").val(param.extra);  
			$("#overtime_salary_edit").val(param.jiaban);
			$("#real_salary_edit").val(param.shifa);      
						
			$("#guarantee_salary_edit").val(param.baozhang);
			$("#total_salary_edit").val(param.heji); 
			$("#endowment_insurance_edit").val(param.yanglao); 
			$("#medical_insurance_edit").val(param.yiliao);  
			$("#maternity_insurance_edit").val(param.shengyu); 
			$("#unemployment_insurance_edit").val(param.shiye); 
			$("#injury_insurance_edit").val(param.gongshang); 
			$("#late_edit").val(param.chidao);
			$("#leave_early_edit").val(param.zaotui);   
			
		break;
	}
	

	$("#editDiv").show();
}
/* 添加页面 */
function add(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
//	    getUserByDept();
		$("#addDiv").show();
	});
}
/* 添加类别页面 */
function addType(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		$("#typeDiv").show();
	});
}
/* 编辑页面 */
function dateEdit(type,id){
	// alert(type);
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var userToken = localStorage.getItem("userToken");
		switch(type){
			/* 它得记录 */
			case 1:
				$("#extraId").val(id);
				var dept = getProject();
				for(var i=0; i<dept.length;i++){
					console.log(dept[i].id)
					$("#department_edit").append($('<option value="'+dept[i].id+'">'+dept[i].name+'</option>'))
				}
			
				 $.ajax({
					type:"GET",
					url:site_url+"/extras?id="+id,
					dataType:"json",
					headers:{'token':userToken},
					success:function(data){
						// alert();
						$("#add_date_edit").val(data.data.extraTime); 
						$("#username_edit").val(data.data.userName); 
						$("#add_date_edit").val(data.data.extraTime.split(" ")[0]); 
						$("#phone_edit").val(data.data.phone); 			
						$("#department_edit").val(data.data.deptId);  
						$("#content_edit").val(data.data.typeId);     
						$("#money_edit").val(data.data.money); 
						$("#remarks_edit").val(data.data.remark); 
					}
				});
				
				break;
			/* 工资明细（不交五险） */
			case 2:
				$("#department_edit").val("安保部"); 
				$("#username_edit").val("张三");
				$("#position_edit").val("楼长"); 
				$("#post_salary_edit").val("232");  
				$("#age_salary_edit").val("200");  
				$("#other_salary_edit").val("300"); 
				$("#overtime_salary_edit").val("432");
				$("#real_salary_edit").val("3242");   
				break;
			/* 工资明细（交纳五险）  */
			case 3:
			 $.ajax({
				type:"GET",
				url:site_url+"/extras?id="+id,
				dataType:"json",
				headers:{'token':userToken},
				success:function(data){
					  
					$("#username_edit").val("张三");     
					$("#position_edit").val("楼长");       
					$("#post_salary_edit").val("300");   
					$("#age_salary_edit").val("200");       
					$("#other_salary_edit").val("200");  
					$("#overtime_salary_edit").val("300");
					$("#real_salary_edit").val("3432");      
								
					$("#guarantee_salary_edit").val("254");
					$("#total_salary_edit").val("3560"); 
					$("#endowment_insurance_edit").val("432"); 
					$("#medical_insurance_edit").val("254");  
					$("#maternity_insurance_edit").val("200"); 
					$("#unemployment_insurance_edit").val("300"); 
					$("#injury_insurance_edit").val("200"); 
				}
			});
				
				break;
			/* 缴存基数  */
			case 4:
			
				var dept = getProject();
				for(var i=0; i<dept.length;i++){
					$("#department_edit").append($('<option value="'+dept[i].id+'">'+dept[i].name+'</option>'))
				}
				$("#userId_edit").val(id);
				$.ajax({
					type:"GET",
					url:site_url+"/salarys/info?id="+id,
					dataType:"json",
					headers:{'token':userToken},
					success:function(data){
						$("#department_edit").val(data.data.deptId);       //部门
						$("#username_edit").val(data.data.userName);           //姓名
						$("#post_salary_edit").val(data.data.gangwei);     //岗位工资
						$("#pension_payment_edit").val(data.data.wxjishu);       //养老缴费
						$("#individual_pension_payment_edit").val(data.data.yanglao);           //个人养老
						$("#individual_medical_payment_edit").val(data.data.yiliao);           //个人医疗
						$("#individual_unemployment_payment_edit").val(data.data.shiye); //个人失业
						$("#individual_maternity_payment_edit").val(data.data.shengyu);       //个人生育
						$("#individual_injury_payment_edit").val(data.data.gongshang);  
					},
				})
				break;
			default:
				break;
		}
		$("#editDiv").show();
	    // layer.alert("编辑！"+id, {icon: 6});
	});
}
/* 删除 */
function dateDelete(type,id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
	   
	    var userToken=localStorage.getItem("userToken");
	    switch(type){
			//它得页面
			case 1:
				layer.confirm('您确定删除吗？', { icon: 3, title: '提示',shade:0 }, function (index) {
					var URL = site_url+"/extras?id="+id; 
						
					$.ajax({
						type:"DELETE",
						url:URL,
						dataType:"json",
						headers:{'token':userToken},
						success:function(data){
							// layer.alert("删除成功！", {icon: 6});
							location.reload();
						}
					});
					layer.close(index);
				});
				
				break;		
			//工资明细页面-不交保险
			case 521:
				break;
			//工资明细页面-缴纳保险
			case 522:
				break;
			//缴存基数页面
			case 53:
				break;	
				
			default:
				break;
		}	
	    
	});
}
/* 添加功能的关闭按钮 */
function addClose(){
	$("#addDiv").hide();
	location.reload();
}
/* 编辑详情功能的关闭按钮 */
function editClose(){
	$("#editDiv").hide();
}
/* 新建类别功能的关闭按钮 */
function typeClose(){
	$("#typeDiv").hide();
}

/*  新建类别的确定按钮 */
function typeSubmit(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		
		var typename=$("#typename").val();       //类别名称
		
		if(typename==""){
			layer.alert("类别名称不能为空！", {icon: 5});
			return;
		}
		if(typename.length>6){
			layer.alert("类别名称不能大于6个字！", {icon: 5});
			return;
		}
		var id=$("#content_edit").length+1;
		/* $("#content").append('<option value="'+id+'">'+typename+'</option>');
		$("#content_edit").append('<option value="'+id+'">'+typename+'</option>'); */
		
		var URL=site_url+"/dicts";
		var userToken=localStorage.getItem("userToken");
		var data = {
			type:"extra",
			description:"它得类别",
			label:typename,
			value:1
		}
		$.ajax({
		    type: 'POST',
		    url: URL,
		    dataType:"json",
			contentType:"application/json",
		    data: JSON.stringify(data),
		    headers:{'token':userToken},
		    success: function (json) {
				var res=json.code;
		        if(res==0){
		            layer.alert("添加成功！", {icon: 6,shade:0});
					typeClose();
					getTypeData();
		        }else{
		            layer.alert("添加失败！", {icon: 5,shade:0});
		        }
		    }
		}); 
	});
}
/* 它得记录添加功能的保存按钮 */
function addSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		
		var username=$("#username").val();       //姓名
		var add_date=$("#add_date").val();       //时间
		var phone=$("#phone").val(); 			 //电话
		var department=$("#department option:selected");   //部门
		var content=$("#content option:selected").val();   //加班类型id
		var name=$("#content option:selected").text();		//加班类型名称
		var money=$("#money").val();             //金额
		var remarks=$("#remarks").val();         //备注
		
		if(username==""){
			layer.alert("姓名不能为空！", {icon: 5});
			return;
		}
		if(add_date==""){
			layer.alert("时间不能为空！", {icon: 5});
			return;
		}
		if(phone==""){
			layer.alert("电话不能为空！", {icon: 5});
			return;
		}
		if(department.val()==""){
			layer.alert("部门不能为空！", {icon: 5});
			return;
		}
		if(content==""){
			layer.alert("内容不能为空！", {icon: 5});
			return;
		}
		if(money==""){
			layer.alert("金额不能为空！", {icon: 5});
			return;
		}
		if(remarks==""){
			layer.alert("备注不能为空！", {icon: 5});
			return;
		}
		// alert(department.text());
		var data = {
			deptId:department.val(),
			money:money,
			remark:remarks,
			typeId:content,
			username:username,
			deptName:department.text(),
			phone:phone,
			name:name
		}
		
		var URL=site_url+"/extras";
		var userToken=localStorage.getItem("userToken");
		$.ajax({
            type: 'POST',
            url: URL,
            dataType:"json",
			contentType:"application/json",
            data: JSON.stringify(data),
            headers:{'token':userToken},
            success: function (json) {
				var res=json.code;
                if(res==0){
                    layer.alert("添加成功！", {icon: 6,shade:0});
					location.reload();
                }else{
                    layer.alert("添加失败！", {icon: 5,shade:0});
                }
            }
        }); 
	});
}
/* 它得记录添加功能的保存按钮 */
function editSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var extraId=$("#extraId").val();   
		var username=$("#username_edit").val();       //姓名
		var add_date=$("#add_date_edit").val();       //时间
		var phone=$("#phone_edit").val(); 			 //电话
		var department=$("#department_edit option:selected");   //部门
		var content=$("#content_edit option:selected").val();   //加班类型id
		var name=$("#content_edit option:selected").text();		//加班类型名称
		var money=$("#money_edit").val();             //金额
		var remarks=$("#remarks_edit").val();         //备注
		
		if(username==""){
			layer.alert("姓名不能为空！", {icon: 5});
			return;
		}
		if(add_date==""){
			layer.alert("时间不能为空！", {icon: 5});
			return;
		}
		if(phone==""){
			layer.alert("电话不能为空！", {icon: 5});
			return;
		}
		if(department.val()==""){
			layer.alert("部门不能为空！", {icon: 5});
			return;
		}
		if(content==""){
			layer.alert("内容不能为空！", {icon: 5});
			return;
		}
		if(money==""){
			layer.alert("金额不能为空！", {icon: 5});
			return;
		}
		if(remarks==""){
			layer.alert("备注不能为空！", {icon: 5});
			return;
		}
		
		var data = {
			id:extraId,
			deptId:department.val(),
			money:money,
			remark:remarks,
			typeId:content,
			username:username,
			deptName:department.text(),
			phone:phone,
			name:name
		}
		
		var URL=site_url+"/extras";
		var userToken=localStorage.getItem("userToken");
		$.ajax({
            type: 'PUT',
            url: URL,
            dataType:"json",
			contentType:"application/json",
            data: JSON.stringify(data),
            headers:{'token':userToken},
            success: function (json) {
				var res=json.code;
                if(res==0){
                    layer.alert("编辑成功！", {icon: 6,shade:0});
					location.reload();
                }else{
                    layer.alert("编辑失败！", {icon: 5,shade:0});
                }
            }
        }); 
	});
}
/* 工资明细(不交五险)添加功能的保存按钮 */
function unpayAddSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		
	    var department=$("#department").val();       //部门
	    var username=$("#username").val();           //姓名
	    var position=$("#position").val();           //职位
	    var post_salary=$("#post_salary").val();     //岗位工资
	    var age_salary=$("#age_salary").val();       //工龄工资
	    var other_salary=$("#other_salary").val();   //它得费用
	    var overtime_salary=$("#overtime_salary").val();//加班费用
	    var real_salary=$("#real_salary").val();        //实发费用
	    
		if(department==""){
			layer.alert("部门不能为空！", {icon: 5});
			return;
		}
		if(username==""){
			layer.alert("姓名不能为空！", {icon: 5});
			return; 
		}
		if(position==""){
			layer.alert("职位不能为空！", {icon: 5});
			return;
		}
		if(post_salary==""){
			layer.alert("岗位工资不能为空！", {icon: 5});
			return;
		}
		if(age_salary==""){
			layer.alert("工龄工资不能为空！", {icon: 5});
			return;
		}
		if(other_salary==""){
			layer.alert("它得费用不能为空！", {icon: 5});
			return;
		}
		if(overtime_salary==""){
			layer.alert("加班费用不能为空！", {icon: 5});
			return;
		}
		if(real_salary==""){
			layer.alert("实发费用不能为空！", {icon: 5});
			return;
		}
	    layer.alert("保存成功！", {icon: 6});
	});
}
/* 工资明细(交纳五险)添加功能的保存按钮 */
function payAddSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		
	    var department=$("#department").val();       //部门
	    var username=$("#username").val();           //姓名
	    var position=$("#position").val();           //职位
	    var post_salary=$("#post_salary").val();     //岗位工资
	    var age_salary=$("#age_salary").val();       //工龄工资
	    var other_salary=$("#other_salary").val();   //它得费用
	    var overtime_salary=$("#overtime_salary").val();//加班费用
	    var real_salary=$("#real_salary").val();        //实发费用
	    
		var guarantee_salary=$("#guarantee_salary").val();        //保障工资
		var total_salary=$("#total_salary").val();                //工资合计
		var endowment_insurance=$("#endowment_insurance").val();  //养老保险
		var medical_insurance=$("#medical_insurance").val();      //医疗保险
		var maternity_insurance=$("#maternity_insurance").val();     //生育保险
		var unemployment_insurance=$("#unemployment_insurance").val();  //失业保险
		var injury_insurance=$("#injury_insurance").val();  //工伤保险
		if(department==""){
			layer.alert("部门不能为空！", {icon: 5});
			return;
		}
		if(username==""){
			layer.alert("姓名不能为空！", {icon: 5});
			return;
		}
		if(position==""){
			layer.alert("职位不能为空！", {icon: 5});
			return;
		}
		if(age_salary==""){
			layer.alert("工龄工资不能为空！", {icon: 5});
			return;
		}
		if(post_salary==""){
			layer.alert("岗位工资不能为空！", {icon: 5});
			return;
		}
		if(guarantee_salary==""){
			layer.alert("保障工资不能为空！", {icon: 5});
			return;
		}
		if(total_salary==""){
			layer.alert("工资合计不能为空！", {icon: 5});
			return;
		}
		if(other_salary==""){
			layer.alert("它得费用不能为空！", {icon: 5});
			return;
		}
		if(overtime_salary==""){
			layer.alert("加班费用不能为空！", {icon: 5});
			return;
		}
		if(endowment_insurance==""){
			layer.alert("养老保险不能为空！", {icon: 5});
			return;
		}
		if(medical_insurance==""){
			layer.alert("医疗保险不能为空！", {icon: 5});
			return;
		}
		if(maternity_insurance==""){
			layer.alert("生育保险不能为空！", {icon: 5});
			return;
		}
		if(unemployment_insurance==""){
			layer.alert("失业保险不能为空！", {icon: 5});
			return;
		}
		if(injury_insurance==""){
			layer.alert("工伤保险不能为空！", {icon: 5});
			return;
		}
		if(real_salary==""){
			layer.alert("实发工资不能为空！", {icon: 5});
			return;
		}
	    layer.alert("保存成功！", {icon: 6});
	});
}

function toinalExport(){
	$("#fileInput").click();
}

/* 文件导入 */
function fileImport(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
	    var formData = new FormData(),
    	fs = $("#fileInput")[0].files;  
  		formData.append("files", fs[0]);
  		var userToken = localStorage.getItem("userToken");
  		
		$.ajax({
			url:site_url+"/extras/uploadfile",
		   	type: 'POST',
	        data: formData,
	        async: false,
	        cache: false,
	        contentType: false,
	        processData: false,
			headers:{'token':userToken},
			success:function(data){
				if (data.code == 0) {
					layer.alert("导入成功！", {icon: 6});
				}else{
					layer.alert(data.msg, {icon: 5});
				}
			}
		});
	    
	});	
}
/* 工资明细的数据切换 */
function changeData(id){
	// alert(id);
	switch(id){
		case 1:
			//标题切换选中样式
			$("#title_one").removeClass("tab-div-unclick");
			$("#title_one").addClass("tab-div-click");
			$("#title_two").removeClass("tab-div-click");
			$("#title_two").addClass("tab-div-unclick");
			//显示对应的数据
			$("#data_one").show();
			$("#data_two").hide();
			//显示对应分页数据
			$("#page").show();
			$("#page2").hide();
		break;
		case 2:
			$("#title_one").removeClass("tab-div-click");
			$("#title_one").addClass("tab-div-unclick");
			$("#title_two").removeClass("tab-div-unclick");
			$("#title_two").addClass("tab-div-click");
			$("#data_one").hide();
			$("#data_two").show();
			$("#page").hide();
			$("#page2").show();
		break;
	}
	
}
/* 搜索功能 */
function search(id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		$('#pageNo').val("1");
		var project=$('#search_project').val();
		var department=$('#search_department').val();
		var date_start = "";
		var date_end = "";
		if (id == 521||id==522) {
			date_start=$('#search_month').val();
		}else{
			date_start=$('#search_date_start').val();
			date_end=$('#search_date_end').val();
		}
		var keyword=$('#search_keyword').val();
		
		var param={
			current:$('#pageNo').val(),
			deptId:department,
			start:date_start,
			end:date_end,
			keyword:keyword
		}
		// var search_month=$('#search_month').val();	
		// if(search_month!=undefined){
		// 	param.start=search_month;
		// }
		requestStatus=false;
		switch(id){
			//它得页面
			case 51:
				getDataAdd(param);
				break;		
			//工资明细页面-不交保险
			case 521:
				param.insurance=false;
				param.projectId=project;
				getDataSalary(param);
				break;
			//工资明细页面-缴纳保险
			case 522:
				param.insurance=true;
				param.projectId=project;
				getDataSalaryPay(param);	
				break;
			//缴存基数页面
			case 53:
				getDataBase(param);
				break;	
			default:
				break;
		}	
	});	
}
/* 缴存基数添加功能的保存按钮 */
function baseAddSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		
	    var department=$("#department").val();       //部门
	    var username=$("#username").val();           //姓名
	    var post_salary=$("#post_salary").val();     //岗位工资
	    var pension_payment=$("#pension_payment").val();       //养老缴费
	    var individual_pension_payment=$("#individual_pension_payment").val();           //个人养老
	    var individual_medical_payment=$("#individual_medical_payment").val();           //个人医疗
	    var individual_unemployment_payment=$("#individual_unemployment_payment").val(); //个人失业
		var individual_maternity_payment=$("#individual_maternity_payment").val();       //个人生育
		var individual_injury_payment=$("#individual_injury_payment").val();             //职位
	    
		if(department==""){
			layer.alert("部门不能为空！", {icon: 5});
			return;
		}
		if(username==""){
			layer.alert("姓名不能为空！", {icon: 5});
			return; 
		}
		if(post_salary==""){
			layer.alert("职位工资不能为空！", {icon: 5});
			return;
		}
		if(pension_payment==""){
			layer.alert("养老缴费不能为空！", {icon: 5});
			return;
		}
		if(individual_pension_payment==""){
			layer.alert("个人养老不能为空！", {icon: 5});
			return;
		}
		if(individual_medical_payment==""){
			layer.alert("个人医疗不能为空！", {icon: 5});
			return;
		}
		if(individual_unemployment_payment==""){
			layer.alert("个人失业不能为空！", {icon: 5});
			return;
		}
		if(individual_maternity_payment==""){
			layer.alert("个人生育不能为空！", {icon: 5});
			return;
		}
		if(individual_injury_payment==""){
			layer.alert("个人工伤不能为空！", {icon: 5});
			return;
		}
	    layer.alert("保存成功！", {icon: 6});
	});
}

function getUserByDept(){
	var userInfo = JSON.parse(localStorage.getItem("userInfo"));
	var URL = site_url+"/users/dept?deptId="+userInfo.deptId+"&size="+50;
	var userToken=localStorage.getItem("userToken");
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			$("#username").html();
			for (var i=0;i<data.data.records.length;i++) {
				var option = $('<option value="'+data.data.records[i].id+'">'+data.data.records[i].name+'</option>')
				$("#username").append(option);
			}
		}
	});
}


function wxjishuChange(){
	
	var wxjishu = $("#pension_payment_edit").val();//养老缴费
	
	var yanglao= multiply(wxjishu,0.08)
	var yiliao=multiply(wxjishu,0.02)
	var shiye=multiply(wxjishu,0.003)
	$("#individual_pension_payment_edit").val(yanglao);           //个人养老
	$("#individual_medical_payment_edit").val(yiliao);           //个人医疗
	$("#individual_unemployment_payment_edit").val(shiye);//个人失业
}

/**
 * 乘法
 * @param {Object} arg1
 * @param {Object} arg2
 */
function multiply(arg1, arg2) {
	let ml = 0
	let s1 = arg1.toString()
	let s2 = arg2.toString()
	try {
		ml += s1.split('.')[1].length
	} catch (e) {}
	
	try {
		ml += s2.split('.')[1].length
	} catch (e) {}
	
	return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, ml)
}
/* 缴存基数编辑功能的保存按钮 */
function baseeditSave(){
	layui.use(['element', 'layer'], function() {	
		var layer = layui.layer;
		
		var pension_payment=$("#pension_payment_edit").val();       //养老缴费
		
		if(pension_payment=="" || pension_payment<0){
			layer.alert("养老缴费不能为空或小于0！", {icon: 5});
			return;
		}
		var userToken = localStorage.getItem("userToken");
	
		var data = {
			userId:$("#userId_edit").val(),
			wxjishu:$("#pension_payment_edit").val(),
			yanglao:$("#individual_pension_payment_edit").val(),           //个人养老
			yiliao:$("#individual_medical_payment_edit").val(),           //个人医疗
			shiye:$("#individual_unemployment_payment_edit").val()//个人失业
		}
		
		$.ajax({
			url:site_url+"/salarys",
			type: 'PUT',
			data: JSON.stringify(data),
		    dataType:"json",
			contentType:"application/json",
			headers:{'token':userToken},
			success:function(data){
				// layer.alert("修改成功", {icon: 6});
				location.reload();
			}
		});
	})
}

function getDeptById(id){
	$("#search_project").val();
	$("#search_department").val();
	var result=[];
	var userToken = localStorage.getItem('userToken');
	$.ajax({
		url:site_url+"/depts/children?id="+id,
		dataType:'json',
		type:'GET',
		async:false,
		headers:{'token':userToken},
		success:function(data){
			result = data.data
		}
	})
	return result;
}
/* 编辑详情功能的关闭按钮 */
function echartsClose(){
	$("#chartsSalaryDiv").hide();
}
/* 薪资总计的折线图 */
function salaryBrokenLine(insurance) {
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;	
		var search_month=$("#search_month").val();
		var year=search_month.substr(0,4);
		var deptId=$("#search_department").val();
		if(deptId==undefined || deptId=="" || deptId==-1){
			layer.alert("请选择部门！", {icon: 5});
			return;
			
		}
		if(year=="" || deptId==""){
			return;
		}
		var URL = site_url+"/deptcollects/year?year="+year+"&deptId="+deptId+"&isInsurance="+insurance;
		var userToken=localStorage.getItem("userToken");
		
	
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(json){
				var data=json.data;
				var month =[12];
				var salary = [12];
				month= ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
				if(data.length==0){
					salary=[0,0,0,0,0,0,0,0,0,0,0,0];
				}else{
					for(var i=0;i<12;i++){
						var money=0;
						for(var j=0;j<data.length;j++){
							var cycle=data[j].cycle;
							var monthData=~~(cycle.substr(5,2));
							if(monthData==(i+1)){
								money=data[j].salary;
							}
							// alert(salary);
						}
						if(money>0){
							salary[i]=money;
						}else{
							
							salary[i]=0;
						}
					}
				}
				var myChart = echarts.init(document.getElementById('chartsSalary'));
				option = {
					title : {
						text: '薪资折线图',
						subtext: '(万元)'
					},
					tooltip : {
						trigger: 'axis'
					},
					legend: {
						data:['工资']
					},
					toolbox: {
						show : false,
						feature : {
							mark : {show: true},
							dataView : {show: true, readOnly: false},
							magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
							restore : {show: true},
							saveAsImage : {show: true}
						}
					},
					calculable : true,
					xAxis : [
						{
							type : 'category',
							boundaryGap : true,
							data :month
						}
					],
					yAxis : [
						{
							type : 'value'
						}
					],
					series : [
						{
							name:'薪资',
							type:'line',
							smooth:false,
							itemStyle: {
								normal: {
									color:'#fb5700', //改变折线点的颜色
									areaStyle: {
										type: 'default',
										color: '#fee7d5'
									},//改变区域的颜色
									lineStyle:{ 
										color:'#fd993a' //改变折线颜色
									} 
								},
							},
							data:salary
						}
					]
				};
			myChart.setOption(option);         
			    
			$("#chartsSalaryDiv").show();
		}	
	});
	});
}
/* 人员总计的折线图 */
function staffBrokenLine(insurance) {
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;	
		var search_month=$("#search_month").val();
		var year=search_month.substr(0,4);
		var deptId=$("#search_department").val();
		if(deptId==undefined || deptId=="" || deptId==-1){
			layer.alert("请选择部门！", {icon: 5});
			return;
			
		}
		var URL = site_url+"/deptcollects/year?year="+year+"&deptId="+deptId+"&isInsurance="+insurance;
		var userToken=localStorage.getItem("userToken");
		
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(json){
			var data=json.data;
			var month =[12];
			var people = [12];
			month= ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
			if(data.length==0){
				people=[0,0,0,0,0,0,0,0,0,0,0,0];
			}else{
				for(var i=0;i<12;i++){
					var peopleNum=0;
					for(var j=0;j<data.length;j++){
						var cycle=data[j].cycle;
						var monthData=~~(cycle.substr(5,2));
						if(monthData==(i+1)){
							peopleNum=data[j].peopleNum;
						}
						// alert(salary);
					}
					if(peopleNum>0){
						people[i]=peopleNum;
					}else{
						
						people[i]=0;
					}
				}
			}
				var myChart = echarts.init(document.getElementById('chartsSalary'));
				option = {
					title : {
						text: '人员折线图',
						subtext: '(人数)'
					},
					tooltip : {
						trigger: 'axis'
					},
					legend: {
						data:['人员']
					},
					toolbox: {
						show : false,
						feature : {
							mark : {show: true},
							dataView : {show: true, readOnly: false},
							magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
							restore : {show: true},
							saveAsImage : {show: true}
						}
					},
					calculable : true,
					xAxis : [
						{
							type : 'category',
							boundaryGap : true,
							data :month
						}
					],
					yAxis : [
						{
							type : 'value'
						}
					],
					series : [
						{
							name:'人员',
							type:'line',
							smooth:false,
				
							itemStyle: {
								normal: {
									color:'#fb5700', //改变折线点的颜色
									areaStyle: {
										type: 'default',
										color: '#fee7d5'
									},//改变区域的颜色
									lineStyle:{ 
										color:'#fd993a' //改变折线颜色
									} 
								},
							},
							data:people
						}
					]
				};
			myChart.setOption(option);         
			$("#chartsSalaryDiv").show();
		}
	});
	});
}
/* 工资冻结 */
function salaryFrozen(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var userToken = localStorage.getItem("userToken");
		var projectId=$("#search_project").val();
		var yearMonth=$("#search_month").val();
		
		if(yearMonth==null){
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = "";
			var monthNum=time.getMonth() + 1;
			//小于10月，前面加0
			if(monthNum<10){
				month = ("0" + (time.getMonth() + 1)).slice(-2);
			}
			var today = time.getFullYear() + "-" + (month);
			yearMonth=today;   
		}
		if(projectId==null || projectId<0){
			layer.alert("请选择项目部！", {icon: 6});
			return;
		}
		var URL = site_url+"/salarys/submit?projectId="+projectId+"&yearMonth="+yearMonth;
		$.ajax({
			url:URL,
			type: 'GET',
		    dataType:"json",
			headers:{'token':userToken},
			success:function(data){
				var res=data.code;
				if(res==0){
					layer.alert("冻结成功！", {icon: 6});
				}else{
					layer.alert(data.msg, {icon: 5});
				}
			}
		});	
	});
}

/* 导出工资明细 */
function exportSalary(insurance){

	var deptId=$("#search_department option:selected").val();
	window.location = site_url+"/salarys/export?start="+$('#search_month').val()+"&keyword="+$('#search_keyword').val()+"&insurance="+insurance+"&deptId="+deptId;
	
}